<template>
  <div id="app">
    <div class="todo-container">
      <div class="todo-wrap"> 
        <Header />
        <List />
        <Footer />
      </div>
    </div>
  </div>
</template>

<script>
import Header from './components/Header.vue'
import List from './components/List.vue'
import Footer from './components/Footer.vue'

export default {
  name: 'App',
  mounted(){
    this.$store.dispatch('requestUpdate')
  },
  // 监视todos的变化
  watch:{
    todos:{
      handler(value){
        // 将todos保存在local Storage中（必须保存为JSON格式）
        localStorage.setItem('todos_key',JSON.stringify(value))
      },
      deep:true,//深度监视，数组内部的对象数据发生变化的时候就会触发
    }
  },
  components: {
    Header,
    List,
    Footer,
    TodoList
  }
}
</script>

<style>
  .todo-container {
    width: 600px;
    margin: 0 auto;
  }
  .todo-container .todo-wrap {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
  }
</style>
